package cn.com.headfree.mouldshow.service.impl;

import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.callback.call.FileServerCall;
import cn.com.headfree.entity.*;
import cn.com.headfree.mouldshow.dao.ExportWordDao;
import cn.com.headfree.mouldshow.service.ExportWordService;
import cn.com.headfree.util.SysDictionaryUtil;
import cn.com.headfree.vo.complex.THonorInfoVo;
import cn.com.headfree.vo.complex.TPatentInfoVo;
import cn.com.headfree.vo.complex.TTecInnovInfoVo;
import cn.com.headfree.vo.complex.TTecManInnovVo;
import com.aspose.words.SaveFormat;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.MiniTableRenderData;
import com.deepoove.poi.data.PictureRenderData;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.data.style.Style;
import com.deepoove.poi.data.style.TableStyle;
import feign.Response;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 导出word服务
 */
@Service("exportWordService")
public class ExportWordServiceImpl implements ExportWordService {

	private static final Logger log = LogManager.getLogger(ExportWordServiceImpl.class);
	@Autowired
	private ExportWordDao exportWordDao;
	@Autowired
	private FileServerCall fileServerCall;

	private static final String FONT_FAMILY = "宋体";
	private static final Integer FONT_SIZE = 10;
	private static final Integer FONT_SIZE_TEXT = 9;
	private static final Integer HIGHT = 2500;

	@Override
	public void exportUserInfoWord(HttpServletResponse response, String erpNo) throws Exception {
		// 查询用户信息
		UserInfoWordVo userInfoWordVo = getUserInfoWord(erpNo);
		if (userInfoWordVo == null) {
			return;
		}

		// 创建文本对象
		XWPFDocument doc = new XWPFDocument();
		// 创建标题
		XWPFParagraph titleParagraph = doc.createParagraph();
		// 设置段落居中
		titleParagraph.setAlignment(ParagraphAlignment.CENTER);
		XWPFRun titleParagraphRun = titleParagraph.createRun();
		titleParagraphRun.setText("人员简历");
		titleParagraphRun.setBold(true);// 加粗
		titleParagraphRun.setFontSize(22);// 字体大小
		titleParagraphRun.setFontFamily(FONT_FAMILY);

		// 段落对象
		XWPFParagraph para;
		// 文本对象
		XWPFRun run;
		// 创建表格
		XWPFTable table = doc.createTable(userInfoWordVo.getRowNum(), 7);
//        table.setCellMargins(3, 5, 3, 5);//设置单元格边距
//        table.addNewCol();//添加新列
//        table.createRow();//添加新行
		// 第一行的值
		String[] title1 = new String[] { "姓 名", userInfoWordVo.getName(), "性 别", userInfoWordVo.getSexName(), "", "",
				"    " };

		// 第二行的值
		String[] title2 = new String[] { "民 族", userInfoWordVo.getNationName(), "籍 贯", userInfoWordVo.getBirthPlace(),
				"出生地", userInfoWordVo.getBornPlace(), " " };

		// 第三行的值
		String[] title3 = new String[] { "入党时间", dateToString(userInfoWordVo.getPartyDate()), "工作时间",
				dateToString(userInfoWordVo.getJobDate()), "专家人才", "", " " };

		// 近三年绩效值
		String[] title4 = new String[] { "近3年绩效",
				userInfoWordVo.getYearEffectInfoList().get(0).getRateYear() != null
						? userInfoWordVo.getYearEffectInfoList().get(0).getRateYear() + "年"
						: "",
				userInfoWordVo.getYearEffectInfoList().get(0).getPerforGradeName(),
				userInfoWordVo.getYearEffectInfoList().get(1).getRateYear() != null
						? userInfoWordVo.getYearEffectInfoList().get(1).getRateYear() + "年"
						: "",
				userInfoWordVo.getYearEffectInfoList().get(1).getPerforGradeName(),
				userInfoWordVo.getYearEffectInfoList().get(2).getRateYear() != null
						? userInfoWordVo.getYearEffectInfoList().get(2).getRateYear() + "年"
						: "",
				userInfoWordVo.getYearEffectInfoList().get(2).getPerforGradeName() };

		XWPFTableRow row;
		CTTcPr cellPr;
		List<XWPFTableCell> hebingList1 = new ArrayList<>();
		List<XWPFTableCell> hebingList2 = new ArrayList<>();
		// 合并列-记录上一列
		XWPFTableCell beforeCell = null;
		// 全日制教育行数
		Integer num1 = userInfoWordVo.getEducateInfoList() != null && userInfoWordVo.getEducateInfoList().size() > 0
				? userInfoWordVo.getEducateInfoList().size()
				: 1;
		// 全日制教育List 下标标记位
		Integer index1 = 0;
		// 在职教育行数
		Integer num2 = userInfoWordVo.getEducateInfoZaizhiList() != null
				&& userInfoWordVo.getEducateInfoZaizhiList().size() > 0
						? userInfoWordVo.getEducateInfoZaizhiList().size()
						: 1;
		// 在职教育List 下标标记位
		Integer index2 = 0;
		// 近三年绩效标记位
		Integer jixiaoIndex = 4 + num1 + num2;
		for (int j = 0; j < userInfoWordVo.getRowNum(); j++) {
			row = table.getRow(j);
			// 第一行
			if (j == 0) {
				for (int i = 0; i < title1.length; i++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, i);
					// 单元格属性
					cellPr = cell.getCTTc().addNewTcPr();
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					// 设置两行之间的行间距
					quchuHang(para);
					run.setText(title1[i]);
					if (i == 0 || i == 2) {
						run.setBold(true);
					}
					if (i == 4) {
						run.setBold(true);
						run.setText("出生年月");
						run.addBreak();// 软回车
						run.setText("（岁）");
					}
					if (i == 5) {
						run.setText(dateToString(userInfoWordVo.getBirthDate()));
						run.addBreak();// 软回车
						run.setText("(" + userInfoWordVo.getSui() + ")");
					}
					if (i == 6) {
						run.setText("   ");
						// 获取头像
//                        TouXiangVo iamges = getTouXiang(erpNo);
//                        InputStream is = null;
//                        try {
//                            if(iamges!=null){
//                                run.addPicture(iamges.getInputStream(), XWPFDocument.PICTURE_TYPE_JPEG, iamges.getName(), Units.toEMU(80), Units.toEMU(100)); // 200x200 pixels
//                            }
//                        }catch (Exception e){
//                            log.error("设置头像报错！", e);
//                        }finally {
//                            if(is != null){
//                                is.close();
//                            }
//                        }

						// 设置宽度
//                        CTTblWidth tblWidth = cellPr.addNewTcW();
//                        tblWidth.setW(BigInteger.valueOf(1250));
//                        tblWidth.setType(STTblWidth.DXA);
						beforeCell = cell;
					}
					if (i == 1 || i == 3 || i == 5) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
					}
				}
			}

			// 第二行
			if (j == 1) {
				for (int y = 0; y < title2.length; y++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, y);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					run.setText(title2[y]);
					if (y == 0 || y == 2 || y == 4) {
						run.setBold(true);
					}
					if (y == 6) {
						// 合并列
						hebingLie(beforeCell, cell);
						beforeCell = cell;
					}
					if (y == 1 || y == 3 || y == 5) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
					}
				}
			}

			// 第三行
			if (j == 2) {
				for (int y = 0; y < title3.length; y++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, y);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					run.setText(title3[y]);
					if (y == 0 || y == 2 || y == 4) {
						run.setBold(true);
					}
					if (y == 5) {
						run.setText(getZhuanjiaList(userInfoWordVo.getExpertTitleInfoList()));
					}

					if (y == 6) {
						// 合并列
						hebingLie(beforeCell, cell);
						beforeCell = cell;
					}
					if (y == 1 || y == 3 || y == 5) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
					}
				}
			}

			// 第四行
			if (j == 3) {
				for (int i = 0; i < 7; i++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, i);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					if (i == 0) {
						run.setBold(true);
						run.setText("技能等级");
					} else if (i == 1) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						run.setText(getJinengList(userInfoWordVo.getSkillLevelInfoList()));
					} else if (i == 2) {
						run.setBold(true);
						run.setText("专业技术资格");
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else if (i == 3) {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					} else if (i == 4) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						run.setText(getZigeList(userInfoWordVo.getProTecInfoList()));
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else if (i != 6) {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					} else if (i == 6) {
						// 合并列
						hebingLie(beforeCell, cell);
					}
				}
			}

			// 学历学位行
			if (j == 4) {
				for (int y = 0; y < 7; y++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, y);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					if (y == 0) {
						run.setBold(true);
						run.setText("学 历");
						run.addBreak();// 软回车
						run.setText("学 位");
						hebingList1.add(cell);
					} else if (y == 1) {
						run.setBold(true);
						run.setText("全日制教育");
						hebingList2.add(cell);
					} else if (y == 2) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						if (userInfoWordVo.getEducateInfoList() != null
								&& userInfoWordVo.getEducateInfoList().size() > 0) {
							run.setText(userInfoWordVo.getEducateInfoList().get(index1).getEducNameName());
						} else {
							run.setText("");
						}

					} else if (y == 3) {
						run.setBold(true);
						run.setText("毕业院校");
						run.addBreak();// 软回车
						run.setText("及专业");
					} else if (y == 4) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						if (userInfoWordVo.getEducateInfoList() != null
								&& userInfoWordVo.getEducateInfoList().size() > 0) {
							run.setText(userInfoWordVo.getEducateInfoList().get(index1).getGradSchool());
							index1++;
						} else {
							run.setText("--");
						}
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}
				num1--;

			} else if (j > 4 && num1 != 0) {
				for (int y = 0; y < 7; y++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, y);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					if (y == 0) {
						run.setBold(true);
						run.setText("学历学位");
						hebingList1.add(cell);
					} else if (y == 1) {
						run.setBold(true);
						run.setText("全日制教育");
						hebingList2.add(cell);
					} else if (y == 2) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						if (userInfoWordVo.getEducateInfoList() != null
								&& userInfoWordVo.getEducateInfoList().size() > 0) {
							run.setText(userInfoWordVo.getEducateInfoList().get(index1).getEducNameName());
						} else {
							run.setText("--");
						}

					} else if (y == 3) {
						run.setBold(true);
						run.setText("毕业院校");
						run.addBreak();// 软回车
						run.setText("及专业");
					} else if (y == 4) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						if (userInfoWordVo.getEducateInfoList() != null
								&& userInfoWordVo.getEducateInfoList().size() > 0) {
							run.setText(userInfoWordVo.getEducateInfoList().get(index1).getGradSchool());
							index1++;
						} else {
							run.setText("--");
						}
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}

				num1--;

			} else if (j > 4 && num1 == 0 && num2 != 0) {
				for (int y = 0; y < 7; y++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, y);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					// 设置两行之间的行间距
					quchuHang(para);
					if (y == 0) {
						run.setBold(true);
						run.setText("学历学位");
						hebingList1.add(cell);
					} else if (y == 1) {
						run.setBold(true);
						run.setText("在职教育");
						hebingList2.add(cell);
					} else if (y == 2) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						if (userInfoWordVo.getEducateInfoZaizhiList() != null
								&& userInfoWordVo.getEducateInfoZaizhiList().size() > 0) {
							run.setText(userInfoWordVo.getEducateInfoZaizhiList().get(index2).getEducNameName());
						} else {
							run.setText("");
						}

					} else if (y == 3) {
						run.setBold(true);
						run.setText("毕业院校");
						run.addBreak();// 软回车
						run.setText("及专业");
					} else if (y == 4) {
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						if (userInfoWordVo.getEducateInfoZaizhiList() != null
								&& userInfoWordVo.getEducateInfoZaizhiList().size() > 0) {
							run.setText(userInfoWordVo.getEducateInfoZaizhiList().get(index2).getGradSchool());
							index2++;
						} else {
							run.setText("--");
						}
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}
				num2--;
			}

			// 现任岗位
			if (j == jixiaoIndex) {
				for (int i = 0; i < 7; i++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, i);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);

					if (i == 0) {
						para.setAlignment(ParagraphAlignment.CENTER);
						run.setBold(true);
						run.setText("现任岗位");
					} else if (i == 1) {
						para.setAlignment(ParagraphAlignment.LEFT);
						run.setText(userInfoWordVo.getCurPost());
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}
			}

			// 近三年绩效
			if (j == (jixiaoIndex + 1)) {
				for (int y = 0; y < title4.length; y++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, y);
					// 设置段落对其方式
					para = shezhiParagraphs(cell);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					run.setText(title4[y]);
					if (y == 0 || y == 1 || y == 3 || y == 5) {
						run.setBold(true);
					}
				}
			}

			// 简历
			if (j == (jixiaoIndex + 2)) {
				// 设置行高
				shezhiHanggao(row);

				for (int i = 0; i < 7; i++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, i);
					para = cell.getParagraphs().get(0);
					para.setFontAlignment(2);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					if (i == 0) {
						para.setAlignment(ParagraphAlignment.CENTER);
						run.setBold(true);
						run.setText("工");
						run.addBreak();// 软回车
						run.setText("作");
						run.addBreak();// 软回车
						run.setText("简");
						run.addBreak();// 软回车
						run.setText("历");
					} else if (i == 1) {
						para.setAlignment(ParagraphAlignment.LEFT);
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						List<String> strList = getJianli(userInfoWordVo.getWorkExpInfoList());
						for (int x = 0; x < strList.size(); x++) {
							if (x != 0) {
								run.addBreak();// 软回车
							}
							run.setText(strList.get(x));
						}

						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}
			}

			// 成果获奖情况
			if (j == (jixiaoIndex + 3)) {
				// 设置行高
				shezhiHanggao(row);

				for (int i = 0; i < 7; i++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, i);
					para = cell.getParagraphs().get(0);
					para.setFontAlignment(2);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					if (i == 0) {
						para.setAlignment(ParagraphAlignment.CENTER);
						run.setBold(true);
						run.setText("成");
						run.addBreak();// 软回车
						run.setText("果");
						run.addBreak();// 软回车
						run.setText("获");
						run.addBreak();// 软回车
						run.setText("奖");
						run.addBreak();// 软回车
						run.setText("情");
						run.addBreak();// 软回车
						run.setText("况");
					} else if (i == 1) {
						para.setAlignment(ParagraphAlignment.LEFT);
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						List<String> strList = getChenguo(userInfoWordVo.getTecInnovInfoList(),
								userInfoWordVo.getTecManInnovList(), userInfoWordVo.getPatentInfoList(),
								userInfoWordVo.getContestInfoList());
						for (int x = 0; x < strList.size(); x++) {
							if (x != 0) {
								run.addBreak();// 软回车
							}
							run.setText(strList.get(x));
						}

						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}
			}

			// 奖惩信息
			if (j == (jixiaoIndex + 4)) {
				// 设置行高
				shezhiHanggao(row);

				for (int i = 0; i < 7; i++) {
					// 创建单元格
					XWPFTableCell cell = getCellByRow(row, i);
					para = cell.getParagraphs().get(0);
					para.setFontAlignment(2);
					// 设置两行之间的行间距
					quchuHang(para);
					// 设置文本属性
					run = shezhiXWPFRun(para);
					if (i == 0) {
						para.setAlignment(ParagraphAlignment.CENTER);
						run.setBold(true);
						run.setText("奖");
						run.addBreak();// 软回车
						run.setText("惩");
						run.addBreak();// 软回车
						run.setText("信");
						run.addBreak();// 软回车
						run.setText("息");
					} else if (i == 1) {
						para.setAlignment(ParagraphAlignment.LEFT);
						// 设置字体大小
						run.setFontSize(FONT_SIZE_TEXT);
						List<String> strList = getJiangchen(userInfoWordVo.getHonorInfoList());
						for (int x = 0; x < strList.size(); x++) {
							if (x != 0) {
								run.addBreak();// 软回车
							}
							run.setText(strList.get(x));
						}
						// 合并行起点
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
					} else {
						// 继续合并
						cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
					}
				}
			}

		}

		XWPFTableCell cellBefore = null;
		for (XWPFTableCell cell : hebingList1) {
			if (cellBefore == null) {
				cellBefore = cell;
				continue;
			}
			// 合并列
			hebingLie(cellBefore, cell);
			cellBefore = cell;
		}

		cellBefore = null;
		for (XWPFTableCell cell : hebingList2) {
			if (cellBefore == null) {
				cellBefore = cell;
				continue;
			}
			if (cellBefore.getText().equals(cell.getText())) {
				// 合并列
				hebingLie(cellBefore, cell);
			}
			cellBefore = cell;
		}

		// wps不兼容docx的表格跨列合并 故docx转doc
		// 二进制OutputStream
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		// 文档写入流
		doc.write(baos);
		InputStream in = new ByteArrayInputStream(baos.toByteArray());
		com.aspose.words.Document asdocx = new com.aspose.words.Document(in);
		OutputStream os = response.getOutputStream();
		log.info(userInfoWordVo.getName() + "人员信息表文件已输出！");
		try {
			// 设置content-disposition响应头控制浏览器以下载的形式打开文件，中文文件名要使用URLEncoder.encode方法进行编码，否则会出现文件名乱码
			response.setHeader("content-disposition",
					"attachment;filename=" + URLEncoder.encode(userInfoWordVo.getName() + "人员简历表.doc", "UTF-8"));
			asdocx.save(os, SaveFormat.DOC);
		} catch (Exception e) {
			log.error("个人信息导出失败！", e);
		} finally {
			if (os != null) {
				os.close();
			}
			if (in != null) {
				in.close();
			}
		}
		return;
	}

	/**
	 * 查询用户信息
	 * 
	 * @param erpNo
	 * @return
	 */
	public UserInfoWordVo getUserInfoWord(String erpNo) {
		// 查询基础信息
		UserInfoWordVo userInfoWordVo = exportWordDao.getUserInfo(erpNo);
		if (userInfoWordVo.getSex() != null) {
			userInfoWordVo.setSexName(SysDictionaryUtil.getNameByValueForDefault("Gender", userInfoWordVo.getSex()));
		}
		if (userInfoWordVo.getNation() != null) {
			userInfoWordVo
					.setNationName(SysDictionaryUtil.getNameByValueForDefault("Nation", userInfoWordVo.getNation()));
		}
		// 计算年龄
		userInfoWordVo.setSui(getNianLing(userInfoWordVo.getBirthDate()));
		// 导出表格行数
		Integer rowNum = 9;
		if (userInfoWordVo != null) {
			// 全日制教育学历
			List<TEducateInfo> educateInfoList = exportWordDao.getEducateInfoList(erpNo, "0");
			if (educateInfoList != null) {
				for (TEducateInfo item : educateInfoList) {
					item.setEducNameName(
							SysDictionaryUtil.getNameByValueForDefault("PersonnelQualifications", item.getEducName()));
					item.setDegreeNameName(
							SysDictionaryUtil.getNameByValueForDefault("AcademicDegree", item.getDegreeName()));
				}
				if (educateInfoList.size() != 0) {
					rowNum = rowNum + educateInfoList.size();
				} else {
					rowNum++;
				}
			}
			// 在职教育
			List<TEducateInfo> educateInfoZaizhiList = exportWordDao.getEducateInfoList(erpNo, "1");
			if (educateInfoZaizhiList != null) {
				for (TEducateInfo item : educateInfoZaizhiList) {
					item.setEducNameName(
							SysDictionaryUtil.getNameByValueForDefault("PersonnelQualifications", item.getEducName()));
					item.setDegreeNameName(
							SysDictionaryUtil.getNameByValueForDefault("AcademicDegree", item.getDegreeName()));
				}
				if (educateInfoZaizhiList.size() != 0) {
					rowNum = rowNum + educateInfoZaizhiList.size();
				} else {
					rowNum++;
				}
			}
			// 专业技术职务
			List<TProTecInfo> proTecInfoList = exportWordDao.getProTecInfoList(erpNo);
			userInfoWordVo.setProTecInfoList(proTecInfoList);
			// 技艺革新
			List<TTecInnovInfo> tecInnovInfoList = exportWordDao.getTecInnovInfoList(erpNo);
			userInfoWordVo.setTecInnovInfoList(tecInnovInfoList);
			// 科技及创新成果
			List<TTecManInnov> tecManInnovList = exportWordDao.getTecManInnovList(erpNo);
			userInfoWordVo.setTecManInnovList(tecManInnovList);
			// 专利论文
			List<TPatentInfo> patentInfoList = exportWordDao.getPatentInfoList(erpNo);
			userInfoWordVo.setPatentInfoList(patentInfoList);
			// 竞赛考试信息
			List<TContestInfo> contestInfoList = exportWordDao.getContestInfoList(erpNo);
			userInfoWordVo.setContestInfoList(contestInfoList);
			// 技能等级
			List<TSkillLevelInfo> skillLevelInfoList = exportWordDao.getSkillLevelInfoList(erpNo);
			userInfoWordVo.setSkillLevelInfoList(skillLevelInfoList);
			// 专家人才称号信息
			List<TExpertTitleInfo> expertTitleInfoList = exportWordDao.getExpertTitleInfoList(erpNo);
			userInfoWordVo.setExpertTitleInfoList(expertTitleInfoList);

			// 绩效信息-近三年
			List<Integer> nianfen = getJinSanNian();
			List<TYearEffectInfo> yearEffectInfoList = new ArrayList<>();
			for (Integer year : nianfen) {
				List<TYearEffectInfo> list = exportWordDao.getYearEffectInfoList(erpNo, year);
				if (list != null && list.size() > 0) {
					list.get(0).setPerforGradeName(SysDictionaryUtil
							.getNameByValueForDefault("PerformLevelRecentThreeYears", list.get(0).getPerforGrade()));
					yearEffectInfoList.add(list.get(0));

				} else {
					TYearEffectInfo ty = new TYearEffectInfo();
					ty.setRateYear(year);
					yearEffectInfoList.add(ty);
				}
			}

			// 简历
			List<TWorkExpInfo> workExpInfoList = exportWordDao.getWorkExpInfoList(erpNo);
			// 奖惩-个人荣誉表
			List<THonorInfo> honorInfoList = exportWordDao.getHonorInfoList(erpNo);

			// 行数
			userInfoWordVo.setRowNum(rowNum);
			userInfoWordVo.setEducateInfoList(educateInfoList);
			userInfoWordVo.setEducateInfoZaizhiList(educateInfoZaizhiList);
			userInfoWordVo.setYearEffectInfoList(yearEffectInfoList);
			userInfoWordVo.setWorkExpInfoList(workExpInfoList);
			userInfoWordVo.setHonorInfoList(honorInfoList);
		}
		return userInfoWordVo;
	}

	private Integer getNianLing(Date birthDay) {
		if (birthDay == null) {
			return 0;
		}
		Calendar cal = Calendar.getInstance();
		if (cal.before(birthDay)) { // 出生日期晚于当前时间，无法计算
			throw new IllegalArgumentException("The birthDay is before Now.It's unbelievable!");
		}
		int yearNow = cal.get(Calendar.YEAR); // 当前年份
		int monthNow = cal.get(Calendar.MONTH); // 当前月份
		int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH); // 当前日期
		cal.setTime(birthDay);
		int yearBirth = cal.get(Calendar.YEAR);
		int monthBirth = cal.get(Calendar.MONTH);
		int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
		int age = yearNow - yearBirth; // 计算整岁数
		if (monthNow <= monthBirth) {
			if (monthNow == monthBirth) {
				if (dayOfMonthNow < dayOfMonthBirth) {
					age--;// 当前日期在生日之前，年龄减一
				}
			} else {
				age--;// 当前月份在生日之前，年龄减一
			}
		}
		return age;
	}

	/**
	 * 时间转换
	 */
	public String dateToString(Date date) {
		if (date == null) {
			return "-";
		}
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd");
		return formatter.format(date);
	}

	/**
	 * 奖惩信息 （包括个人荣誉）
	 * 
	 * @param list
	 * @return
	 */
	public List<String> getJiangchen(List<THonorInfo> list) {
		List<String> result = new ArrayList<>();
		if (list != null) {
			for (THonorInfo item : list) {
				// StringBuilder sb = new StringBuilder("● ");
				StringBuilder sb = new StringBuilder("");
				sb.append(dateToString(item.getAcquTime()));
				sb.append(" ").append(item.getAwardOrg() == null ? "" : item.getAwardOrg());
				sb.append(" ").append(item.getHonorTitle() == null ? "" : item.getHonorTitle());
				result.add(sb.toString());
			}
		}
		return result;
	}

	/**
	 * 简历信息
	 * 
	 * @param list
	 * @return
	 */
	public List<String> getJianli(List<TWorkExpInfo> list) {
		List<String> result = new ArrayList<>();
		if (list != null) {
			for (TWorkExpInfo item : list) {
				// StringBuilder sb = new StringBuilder("● ");
				StringBuilder sb = new StringBuilder("");
				sb.append(dateToString(item.getStartDate())).append("-").append(dateToString(item.getEndDate()));
				sb.append(" ").append(item.getCompany() == null ? "" : item.getCompany());
				sb.append(" ").append(item.getDept() == null ? "" : item.getDept());
				result.add(sb.toString());
			}
		}
		return result;
	}

	/**
	 * 专家人才称号
	 * 
	 * @param list
	 * @return
	 */
	public String getZhuanjiaList(List<TExpertTitleInfo> list) {
		StringBuilder sb = new StringBuilder();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					sb.append("、");
				}
				sb.append(SysDictionaryUtil.getNameByValueForDefault("TalentTitle", list.get(i).getEmpTitle()) == null
						? ""
						: SysDictionaryUtil.getNameByValueForDefault("TalentTitle", list.get(i).getEmpTitle()));
			}
		}
		return sb.toString();
	}

	/**
	 * 技能等级
	 * 
	 * @param list
	 * @return
	 */
	public String getJinengList(List<TSkillLevelInfo> list) {
		StringBuilder sb = new StringBuilder();
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					sb.append("、");
				}
				sb.append(SysDictionaryUtil.getNameByValueForDefault("QualificationLevel",
						list.get(i).getQualifiLevel()) == null ? ""
								: SysDictionaryUtil.getNameByValueForDefault("QualificationLevel",
										list.get(i).getQualifiLevel()));
			}
		}
		return sb.toString();
	}

	/**
	 * 专业技术资格
	 * 
	 * @param list
	 * @return
	 */
	public String getZigeList(List<TProTecInfo> list) {
		StringBuilder sb = new StringBuilder();
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					sb.append("、");
				}
				sb.append(list.get(i).getSubjName() == null ? "" : list.get(i).getSubjName());
			}
		}
		return sb.toString();
	}

	/**
	 * 成果获奖情况
	 * 
	 * @return
	 */
	public List<String> getChenguo(List<TTecInnovInfo> list1, List<TTecManInnov> list2, List<TPatentInfo> list3,
                                   List<TContestInfo> list4) {
		List<String> result = new ArrayList<>();
		for (TTecInnovInfo item : list1) {
			// StringBuilder sb = new StringBuilder("● ");
			StringBuilder sb = new StringBuilder("");
			sb.append(dateToString(item.getAwardDate()));
			sb.append(" ").append(item.getAwardOrg() == null ? "" : item.getAwardOrg());
			sb.append(" ").append(item.getAwardName() == null ? "" : item.getAwardName());
			result.add(sb.toString());
		}
		for (TTecManInnov item : list2) {
			// StringBuilder sb = new StringBuilder("● ");
			StringBuilder sb = new StringBuilder("");
			sb.append(dateToString(item.getAwardDate()));
			sb.append(" ").append(item.getAwardOrg() == null ? "" : item.getAwardOrg());
			sb.append(" ").append(item.getAwardName() == null ? "" : item.getAwardName());
			result.add(sb.toString());
		}
		for (TPatentInfo item : list3) {
			// StringBuilder sb = new StringBuilder("● ");
			StringBuilder sb = new StringBuilder("");
			sb.append(dateToString(item.getApplyDate()));
			sb.append(" ").append(item.getPatentName() == null ? "" : item.getPatentName());
			result.add(sb.toString());
		}
		for (TContestInfo item : list4) {
			// StringBuilder sb = new StringBuilder("● ");
			StringBuilder sb = new StringBuilder("");
			sb.append(dateToString(item.getAwardDate()));
			sb.append(" ").append(item.getCompName() == null ? "" : item.getCompName());
			sb.append(" ").append(item.getAwardName() == null ? "" : item.getAwardName());
			result.add(sb.toString());
		}
		return result;
	}

	/**
	 * 查询近三年
	 * 
	 * @return
	 */
	public List<Integer> getJinSanNian() {
		List<Integer> result = new ArrayList<>();
		Calendar date = Calendar.getInstance();
		Integer year = date.get(Calendar.YEAR);
		result.add(year - 3);
		result.add(year - 2);
		result.add(year - 1);
		return result;
	}

	/**
	 * 创建单元格并垂直居中
	 */
	public XWPFTableCell getCellByRow(XWPFTableRow row, Integer i) {
		// 创建单元格
		XWPFTableCell cell = row.getCell(i);
		// 垂直居中
		cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
		return cell;
	}

	/**
	 * 设置段落对其方式
	 * 
	 * @param cell
	 * @return
	 */
	public XWPFParagraph shezhiParagraphs(XWPFTableCell cell) {
		// 第一个段落
		XWPFParagraph para = cell.getParagraphs().get(0);
		// 设置对齐方式
		para.setAlignment(ParagraphAlignment.CENTER);
		// 段落的对齐方式 1左 2中 3右 4往上 左 不可写0和负数
		para.setFontAlignment(2);
		return para;
	}

	/**
	 * 文本对象
	 * 
	 * @param para
	 * @return
	 */
	public XWPFRun shezhiXWPFRun(XWPFParagraph para) {
		// 一个XWPFRun代表具有相同属性的一个区域：一段文本
		XWPFRun run = para.createRun();
		// 设置字体
		run.setFontFamily(FONT_FAMILY);
		// 设置字体大小
		run.setFontSize(FONT_SIZE);
		return run;
	}

	/**
	 * 设置行高
	 * 
	 * @param row
	 */
	public void shezhiHanggao(XWPFTableRow row) {
		CTTrPr trPr = row.getCtRow().addNewTrPr();
		CTHeight ht = trPr.addNewTrHeight();
		ht.setVal(BigInteger.valueOf(HIGHT));
	}

	/**
	 * 去除字体行间距
	 */
	public void quchuHang(XWPFParagraph para) {
		CTPPr ppr = para.getCTP().getPPr();
		if (ppr == null) {
			ppr = para.getCTP().addNewPPr();
		}

		CTSpacing spacing = ppr.isSetSpacing() ? ppr.getSpacing() : ppr.addNewSpacing();
		spacing.setAfter(BigInteger.valueOf(0));
		spacing.setBefore(BigInteger.valueOf(0));
		spacing.setLineRule(STLineSpacingRule.AUTO);
		spacing.setLine(BigInteger.valueOf(240));
	}

	/**
	 * 合并列
	 */
	public void hebingLie(XWPFTableCell cellBefore, XWPFTableCell cell) {
		// 设置合并列的开始点
		CTVMerge vmerge = CTVMerge.Factory.newInstance();
		vmerge.setVal(STMerge.RESTART);
		cellBefore.getCTTc().getTcPr().setVMerge(vmerge);
		cell.getCTTc().getTcPr().setVMerge(vmerge);

		// 设置合并列的开始点
		CTVMerge vmerge1 = CTVMerge.Factory.newInstance();
		vmerge1.setVal(STMerge.CONTINUE);
		cellBefore.getCTTc().getTcPr().setVMerge(vmerge1);
		cell.getCTTc().getTcPr().setVMerge(vmerge1);
	}

	/**
	 * 获取头像
	 * 
	 * @param erpNo
	 * @return
	 */
	public TouXiangVo getTouXiang(String erpNo) {
		TouXiangVo touXiangVo = null;
		InputStream inputStream = null;
		String fileId = null;
		String name = null;
		try {
			// 通过ERP号查询头像Id
			ResultData resultData = fileServerCall.findFileList("personManage", erpNo, "userHead");
			JSONArray jsonArray = null;
			JSONObject obj = null;
			if (null != resultData) {
				log.info("获取头像数据为--" + resultData.toString());
				if (null != resultData.getData()) {
					jsonArray = JSONArray.fromObject(resultData.getData());
					if ((null != jsonArray) && (0 < jsonArray.size())) {
						for (int i = 0; i < jsonArray.size(); i++) {
							obj = (JSONObject) jsonArray.get(i);
							if (null != obj) {
								fileId = obj.getString("id");
								name = obj.getString("oldFileName");
							}
						}
					}
				}
			}
			// 下载文件
			if (fileId != null) {
				try {
					Response response = fileServerCall.downloadFile(fileId);

					// 判断是否下载成功
					if (response.status() == 200) {
						log.info("获取头像成功");
						Response.Body body = response.body();
						inputStream = body.asInputStream();
						touXiangVo = new TouXiangVo();
						touXiangVo.setName(name);
						touXiangVo.setInputStream(inputStream);
					}

				} catch (Exception e) {
					log.error("下载文件失败！", e);
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}

        return touXiangVo;
    }


	@Override
	public void exportUserInfoWordByTpl(HttpServletResponse response, String erpNo, String templateName,
			String filename, ResourceLoader resourceLoader) throws Exception {
		// 查询用户信息
		UserInfoWordTplVo result = getUserInfoWordTplVo(erpNo);
		if (result == null) {
			return;
		}

		XWPFTemplate template = null;
		FileOutputStream out = null;
		try {

			Resource resource = resourceLoader.getResource("classpath:templates/resums.docx");
			InputStream is = resource.getInputStream();
			template = XWPFTemplate.compile(is).render(result);

			String tempfilePath = UUID.randomUUID() + "简历.docx";
			out = new FileOutputStream(tempfilePath);
			template.write(out);
			out.flush();
			// response导出
			log.info("start response wordfile");
			responseWord(response, tempfilePath, filename);
			log.info("response wordfile success");
		} catch (Exception e) {
			log.error("生成本地word异常:", e);
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (Exception e) {
				log.error("关闭out异常", e);
			}

			try {
				if (template != null) {
					template.close();
				}
			} catch (Exception e) {
				log.error("关闭template异常", e);
			}
		}

		// WordExportUtil.exportWordByTplResUme(response, userInfoWordVo, templateName,
		// filename, resourceLoader);
	}

	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
	// 时间格式
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");

	private void responseWord(HttpServletResponse response, String path, String filename) {
		File file = null;
		InputStream in = null;
		ServletOutputStream out = null;
		try {
			// 简历名称，名称+时间戳+文档后缀名
//            String downloadFileName="个人信息"+simpleDateFormat.format(new Date())+".docx";
			String downloadFileName = filename + simpleDateFormat.format(new Date()) + ".docx";
			file = new File(path);
			in = new FileInputStream(file);
			response.setCharacterEncoding("utf-8");
//            response.setContentType("application/msword");
			response.setHeader("Cache-Control", "");
			response.setContentType("application/octet-stream");
			response.setHeader("Content-Disposition",
					"attachment;filename=".concat(String.valueOf(URLEncoder.encode(downloadFileName, "UTF-8"))));
			out = response.getOutputStream();
			byte[] buffer = new byte[512];
			int bytesToRead = -1;
			// 用响应对象response中的输出流读取生成好的文件
			while ((bytesToRead = in.read(buffer)) != -1) {
				out.write(buffer, 0, bytesToRead);
			}
		} catch (Exception ex) {
			log.error("product word fail..", ex);
		} finally {
			if (in != null)
				try {
					in.close();
					if (out != null)
						out.close();
					if (file != null)
						file.delete(); // 删除临时文件
				} catch (IOException e) {
//                System.out.println("删除删除临时文件出错");
					log.error("删除删除临时文件出错:" + e);
				}
		}
	}

    public UserInfoWordTplVo getUserInfoWordTplVo(String erpNo) {
    	UserInfoWordTplVo result = new UserInfoWordTplVo();
    	UserInfoWordVo userInfoWordVo = getUserInfoWord(erpNo);
    	//
    	//姓名
    	result.setName(userInfoWordVo.getName());
    	//性别
    	result.setSex(userInfoWordVo.getSexName());
    	//出生日期
    	result.setBirthDate(sdf.format(userInfoWordVo.getBirthDate()));
    	//名族
    	result.setNation(userInfoWordVo.getNationName());
    	//籍贯
    	result.setBirthPlace(userInfoWordVo.getBirthPlace());
    	//出生地
    	result.setBornPlace(userInfoWordVo.getBornPlace());
    	//入党时间
    	result.setPartyDate(sdf.format(userInfoWordVo.getPartyDate()));
    	//工作时间
    	result.setJobDate(sdf.format(userInfoWordVo.getJobDate()));
    	//现任岗位
    	result.setCurPost(userInfoWordVo.getCurPost());

    	//获取头像
        TouXiangVo iamges = getTouXiang(erpNo);
        if(iamges != null && iamges.getInputStream()!=null) {
        	//String suffix = iamges.getName().substring(iamges.getName().lastIndexOf("."));
            result.setPic(new PictureRenderData(100, 160, iamges.getName().substring(iamges.getName().lastIndexOf(".")), iamges.getInputStream()));
//            result.setPic(Pictures.ofStream(iamges.getInputStream(), PictureType.suggestFileType(iamges.getName().substring(iamges.getName().lastIndexOf(".")))).size(100, 160).create());
        }

    	//专家人才
    	result.setZjrc(getZhuanjiaList(userInfoWordVo.getExpertTitleInfoList()));
    	//技能等级
    	result.setJndj(getJinengList(userInfoWordVo.getSkillLevelInfoList()));
    	//专业技术资格
    	result.setZyjszg(getZigeList(userInfoWordVo.getProTecInfoList()));
    	//全日制教育
    	if(userInfoWordVo.getEducateInfoList()!= null && userInfoWordVo.getEducateInfoList().size()>0) {
    	   	//学历
    		result.setXueli(userInfoWordVo.getEducateInfoList().get(userInfoWordVo.getEducateInfoList().size()-1).getEducNameName());
    		//学位
    		result.setXuewei(userInfoWordVo.getEducateInfoList().get(userInfoWordVo.getEducateInfoList().size()-1).getDegreeNameName());
    		//userInfoWordVo.getEducateInfoList().get(userInfoWordVo.getEducateInfoList().size()-1);
    		//学校
    		result.setXuexiao(userInfoWordVo.getEducateInfoList().get(userInfoWordVo.getEducateInfoList().size()-1).getGradSchool());
    		//专业
    		result.setZhuanye(userInfoWordVo.getEducateInfoList().get(userInfoWordVo.getEducateInfoList().size()-1).getMajor());
    	}
    	//在职教育
    	if(userInfoWordVo.getEducateInfoZaizhiList()!= null && userInfoWordVo.getEducateInfoZaizhiList().size()>0) {

    		//学历
    		result.setZzhix(userInfoWordVo.getEducateInfoZaizhiList().get(userInfoWordVo.getEducateInfoZaizhiList().size()-1).getEducNameName());
    		//学位
    		result.setZzjy(userInfoWordVo.getEducateInfoZaizhiList().get(userInfoWordVo.getEducateInfoZaizhiList().size()-1).getDegreeNameName());
    		//userInfoWordVo.getEducateInfoList().get(userInfoWordVo.getEducateInfoList().size()-1);
    		//学校
    		result.setZzxx(userInfoWordVo.getEducateInfoZaizhiList().get(userInfoWordVo.getEducateInfoZaizhiList().size()-1).getGradSchool());
    		//专业
    		result.setZzzy(userInfoWordVo.getEducateInfoZaizhiList().get(userInfoWordVo.getEducateInfoZaizhiList().size()-1).getMajor());


    		//userInfoWordVo.getEducateInfoZaizhiList().get(userInfoWordVo.getEducateInfoZaizhiList().size()-1);
    	}
    	//近三年绩效
    	result.setOne(userInfoWordVo.getYearEffectInfoList().get(0).getRateYear()+"");
    	result.setOnex(userInfoWordVo.getYearEffectInfoList().get(0).getPerforGradeName()==null?"":userInfoWordVo.getYearEffectInfoList().get(0).getPerforGradeName());

    	result.setTwo(userInfoWordVo.getYearEffectInfoList().get(1).getRateYear()+"");
    	result.setTwox(userInfoWordVo.getYearEffectInfoList().get(1).getPerforGradeName()==null?"":userInfoWordVo.getYearEffectInfoList().get(1).getPerforGradeName());


    	result.setThree(userInfoWordVo.getYearEffectInfoList().get(2).getRateYear()+"");
    	result.setThreex(userInfoWordVo.getYearEffectInfoList().get(2).getPerforGradeName()==null?"":userInfoWordVo.getYearEffectInfoList().get(2).getPerforGradeName());

		// 工作简历
//		List<String> strList1 = getJianli(userInfoWordVo.getWorkExpInfoList());

		// 简历
//		result.setWklist(new NumbericRenderData(new ArrayList<TextRenderData>() {
//			{
//				strList1.stream().forEach(p -> {
//					add(new TextRenderData(p));
//				});
//			}
//		}));

		Style headTextStyle = new Style();
		TableStyle headStyle = new TableStyle();
		TableStyle rowStyle = new TableStyle();

		headTextStyle.setFontFamily("Hei");
		headTextStyle.setFontSize(9);
		headTextStyle.setColor("7F7F7F");

		headStyle.setBackgroundColor("F2F2F2");
		headStyle.setAlign(STJc.CENTER);

		rowStyle = new TableStyle();
		rowStyle.setAlign(STJc.CENTER);

		// 工作简历
		RowRenderData headerWktablelist = RowRenderData.build(
				new TextRenderData("工作时间"),
				new TextRenderData("单位"),
				new TextRenderData("部门"),
				new TextRenderData("职务"));
		headerWktablelist.setRowStyle(headStyle);

		ArrayList rowWktablelist = new ArrayList<RowRenderData>(){};
		if (null!=userInfoWordVo.getWorkExpInfoList() && userInfoWordVo.getWorkExpInfoList().size()>0) {
			for (TWorkExpInfo item : userInfoWordVo.getWorkExpInfoList()) {
				String dateStr = dateToString(item.getStartDate())+"-"+dateToString(item.getEndDate());
				String company = item.getCompany() == null ? "" : item.getCompany();
				String dept = item.getDept() == null ? "" : item.getDept();
				String post = item.getPost() == null ? "" : item.getPost();
				RowRenderData row = RowRenderData.build(dateStr, company,dept,post);
				row.setRowStyle(rowStyle);
				rowWktablelist.add(row);
			}
		}
		MiniTableRenderData  miniTableRenderDataWktablelist = new MiniTableRenderData(headerWktablelist, rowWktablelist,16.17F);
		miniTableRenderDataWktablelist.setStyle(headStyle);
		result.setWktablelist(miniTableRenderDataWktablelist);

		// 竞赛考试信息
		RowRenderData headercontesttablelist = RowRenderData.build(
				new TextRenderData("获奖时间"),
				new TextRenderData("竞赛考试名次"),
				new TextRenderData("是否获得称号"),
				new TextRenderData("竞赛考试获奖名称"));
		headercontesttablelist.setRowStyle(headStyle);

		ArrayList rowcontesttablelist = new ArrayList<RowRenderData>(){};
		if (null!=userInfoWordVo.getContestInfoList() && userInfoWordVo.getContestInfoList().size()>0) {
			for (TContestInfo item : userInfoWordVo.getContestInfoList()) {
				String dateStr = dateToString(item.getAwardDate());
				String company = item.getCompRankName() == null ? "" : item.getCompRankName();
				String dept = item.getGetTitle() == null ? "" : item.getGetTitle().equals("0")?"是":"否";
				String post = item.getAwardName() == null ? "" : item.getAwardName();
				RowRenderData row = RowRenderData.build(dateStr, company,dept,post);
				row.setRowStyle(rowStyle);
				rowcontesttablelist.add(row);
			}
		}
		MiniTableRenderData  miniTableRenderDatacontesttablelist = new MiniTableRenderData(headercontesttablelist, rowcontesttablelist,16.17F);
		miniTableRenderDatacontesttablelist.setStyle(headStyle);
		result.setContesttablelist(miniTableRenderDatacontesttablelist);

		// 专利、软件著作权
		RowRenderData headerpatenttablelist = RowRenderData.build(
				new TextRenderData("专利申请日/开发完成日期"),
				new TextRenderData("专利/软著名称"),
				new TextRenderData("类型"),
				new TextRenderData("授权公告日/软著登记日"));
		headerpatenttablelist.setRowStyle(headStyle);

		ArrayList rowpatenttablelist = new ArrayList<RowRenderData>(){};
		List<TPatentInfoVo> patentInfoVoList = exportWordDao.getPatentInfoVoList(erpNo);
		if (null!=patentInfoVoList && patentInfoVoList.size()>0) {
			for (TPatentInfoVo item : patentInfoVoList) {
				String dateStr = dateToString(item.getApplyDate());
				String company = item.getPatentName() == null ? "" : item.getPatentName();
				String dept = item.getPatentTypeName() == null ? "" : item.getPatentTypeName();
				String post = item.getDeclDate() == null ? "" : dateToString(item.getDeclDate());
				RowRenderData row = RowRenderData.build(dateStr, company,dept,post);
				row.setRowStyle(rowStyle);
				rowpatenttablelist.add(row);
			}
		}
		MiniTableRenderData  miniTableRenderDatapatenttablelist = new MiniTableRenderData(headerpatenttablelist, rowpatenttablelist,16.17F);
		miniTableRenderDatapatenttablelist.setStyle(headStyle);
		result.setPatenttablelist(miniTableRenderDatapatenttablelist);

		// 技艺革新信息（QC）
		RowRenderData headertecInnovtablelist = RowRenderData.build(
				new TextRenderData("获奖时间"),
				new TextRenderData("成果名称"),
				new TextRenderData("获奖级别"),
				new TextRenderData("获奖等级"));
		headertecInnovtablelist.setRowStyle(headStyle);

		ArrayList rowtecInnovtablelist = new ArrayList<RowRenderData>(){};
		List<TTecInnovInfoVo> tecInnovInfoVoList = exportWordDao.getTecInnovInfoVoList(erpNo);
		if (null!=tecInnovInfoVoList&& tecInnovInfoVoList.size()>0) {
			for (TTecInnovInfoVo item : tecInnovInfoVoList) {
				String dateStr = dateToString(item.getAwardDate());
				String company = item.getAchiName() == null ? "" : item.getAchiName();
				String dept = item.getAwardLevelName() == null ? "" : item.getAwardLevelName();
				String post = item.getAwardGradeName() == null ? "" : item.getAwardGradeName();
				RowRenderData row = RowRenderData.build(dateStr, company,dept,post);
				row.setRowStyle(rowStyle);
				rowtecInnovtablelist.add(row);
			}
		}
		MiniTableRenderData  miniTableRenderDatatecInnovtablelist = new MiniTableRenderData(headertecInnovtablelist, rowtecInnovtablelist,16.17F);
		miniTableRenderDatatecInnovtablelist.setStyle(headStyle);
		result.setTecInnovtablelist(miniTableRenderDatatecInnovtablelist);

		// 科技及管理、创新成果
		RowRenderData headercgtablelist = RowRenderData.build(
				new TextRenderData("获奖时间"),
				new TextRenderData("成果名称"),
				new TextRenderData("奖项等级"),
				new TextRenderData("成果类别"));
		headercgtablelist.setRowStyle(headStyle);

		ArrayList rowcgtablelist = new ArrayList<RowRenderData>(){};
		List<TTecManInnovVo> tecManInnovVoList = exportWordDao.getTecManInnovVoList(erpNo);
		if (null!=tecManInnovVoList&& tecManInnovVoList.size()>0) {
			for (TTecManInnovVo item : tecManInnovVoList) {
				String dateStr = dateToString(item.getAwardDate());
				String company = item.getAchiName() == null ? "" : item.getAchiName();
				String dept = item.getAwardGradeName() == null ? "" : item.getAwardGradeName();
				String post = item.getAchiTypeName() == null ? "" : item.getAchiTypeName();
				RowRenderData row = RowRenderData.build(dateStr, company,dept,post);
				row.setRowStyle(rowStyle);
				rowcgtablelist.add(row);
			}
		}
		MiniTableRenderData  miniTableRenderDatacgtablelist = new MiniTableRenderData(headercgtablelist, rowcgtablelist,16.17F);
		miniTableRenderDatacgtablelist.setStyle(headStyle);
		result.setCgtablelist(miniTableRenderDatacgtablelist);

		// 个人荣誉
		RowRenderData headerhonortablelist = RowRenderData.build(
				new TextRenderData("时间"),
				new TextRenderData("荣誉称号"),
				new TextRenderData("荣誉级别"),
				new TextRenderData("荣誉类型"));
		headerhonortablelist.setRowStyle(headStyle);

		ArrayList rowhonortablelist = new ArrayList<RowRenderData>(){};
		List<THonorInfoVo> tHonorInfoVoList = exportWordDao.getHonorInfoVoList(erpNo);
		if (null!=tHonorInfoVoList&& tHonorInfoVoList.size()>0) {
			for (THonorInfoVo item : tHonorInfoVoList) {
				String dateStr = dateToString(item.getAcquTime());
				String company = item.getHonorTitle() == null ? "" : item.getHonorTitle();
				String dept = item.getHonorLevelName() == null ? "" : item.getHonorLevelName();
				String post = item.getHonorTypeName() == null ? "" : item.getHonorTypeName();
				RowRenderData row = RowRenderData.build(dateStr, company,dept,post);
				row.setRowStyle(rowStyle);
				rowhonortablelist.add(row);
			}
		}
		MiniTableRenderData  miniTableRenderDatahonortablelist = new MiniTableRenderData(headerhonortablelist, rowhonortablelist,16.17F);
		miniTableRenderDatahonortablelist.setStyle(headStyle);
		result.setHonortablelist(miniTableRenderDatahonortablelist);

		// 成果获奖情况
		/*List<String> strList2 = getChenguo(userInfoWordVo.getTecInnovInfoList(), userInfoWordVo.getTecManInnovList(),
				userInfoWordVo.getPatentInfoList(), userInfoWordVo.getContestInfoList());
		result.setCglist(new NumbericRenderData(new ArrayList<TextRenderData>() {
			{
				strList2.stream().forEach(p -> {
					add(new TextRenderData(p));
				});
			}
		}));

		// 奖惩信息
		List<String> strList3 = getJiangchen(userInfoWordVo.getHonorInfoList());
		result.setJclist(new NumbericRenderData(new ArrayList<TextRenderData>() {
			{
				strList3.stream().forEach(p -> {
					add(new TextRenderData(p));
				});
			}
		}));*/

		return result;
	}

}

